<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="<c:url value="/resource/dwz/js/jquery-1.7.2.min.js"/>" type="text/javascript"></script>
<script type='text/javascript' src="<c:url value="/resource/js/jqueryui/js/jquery-ui-1.10.3.custom.js"/>"></script>
<link rel="stylesheet" type="text/css" href="<c:url value="/resource/js/jqueryui/css/cupertino/jquery-ui-1.10.3.custom.css"/>" />
<script type="text/javascript">
	$(function(){
		//load orderitems
		$('#addOrderItemBtn').click(function(){
			loadOrderItemFrag();
		});
				
		$('#orderItemWrapper').delegate('.line-item-delete','mouseover',function(event){
			$(this).addClass('ui-state-hover');
			$(this).removeClass('ui-state-active');
		}).delegate('.line-item-delete','mouseout',function(){
			$(this).removeClass('ui-state-hover');
			$(this).removeClass('ui-state-active');
		}).delegate('.line-item-delete','mousedown',function(){
			$(this).addClass('ui-state-active');
			var context = $(this).closest('.order-item');
			if(window.confirm('您是否要删除该订单项？')){
				context.remove();
			}
			
		}).delegate('.line-item-delete','mouseup',function(){
			$(this).removeClass('ui-state-active');
		}).delegate('input[name^=isNeedDoorFrame_]','click',function(){
			var context = $(this).closest('.order-item');
			if($(this).val()==='true'){
				$('.door-frame-section',$(this).closest('.order-item')).css('display','block');
				$('input[name=isNeedDoorFrame]',context).val('true');
			}
			if($(this).val()==='false'){
				$('.door-frame-section',$(this).closest('.order-item')).css('display','none');
				$('input[name=isNeedDoorFrame]',context).val('false');
			}
		}).delegate('input[name^=isNeedDoorLeaf_]','click',function(){
			var context = $(this).closest('.order-item');
			if($(this).val()==='true'){
				$('.door-leaf-section',$(this).closest('.order-item')).css('display','block');
				$('input[name=isNeedDoorLeaf]',context).val('true');
			}
			if($(this).val()==='false'){
				$('.door-leaf-section',$(this).closest('.order-item')).css('display','none');
				$('input[name=isNeedDoorLeaf]',context).val('false');
			}
		}).delegate('input[name^=isNeedLineShape_]','click',function(){
			var context = $(this).closest('.order-item');
			if($(this).val()==='true'){
				$('.line-shape-section',$(this).closest('.order-item')).css('display','block');
				$('input[name=isNeedLineShape]',context).val('true');
			}
			if($(this).val()==='false'){
				$('.line-shape-section',$(this).closest('.order-item')).css('display','none');
				$('input[name=isNeedLineShape]',context).val('false');
			}
		});
	});

	var itemIndex = 0;
	var products =[];
	function loadOrderItemFrag(){
		$.ajax({
			  type: "POST",
			  url: '<c:url value="/orders/loadOrderItemFrag.do?orderid=${order.id}&itemIndex="/>'+(itemIndex++),	
			  dataType:'html',
			  success: function(frag){
			     $('#orderItemWrapper').append(frag);
			  }
		});
	}
	
	function loadProducts(){
		$.ajax({
			  type: "POST",
			  url: '<c:url value="/orders/loadProducts.do"/>',
			  dataType:'json',
			  success: function(json){
				  products=json;
			  }
		});
	}
	//loadProducts();
</script>
<style type="text/css">
label,input {
	display: block;
	float: left;
}

label {
	width: 80px;
	text-align: left;
}

.short {
	width: 40px;
}

.line-item {
	margin-bottom: .5em;
}

.ui-autocomplete {
	max-height: 100px;
	overflow-y: auto;
	/* prevent horizontal scrollbar */
	overflow-x: hidden;
}
/* IE 6 doesn't support max-height
	 * we use height instead, but this forces the menu to always be this tall
	 */
* html .ui-autocomplete {
	height: 100px;
}
</style>
<title>添加订单</title>
</head>
<body class="ui-widget" style="font-size: 80%;" onload="loadProducts();">
	<form action="<c:url value="/orders/saveOrUpdateOrder.do"/>" method="post" id="ordersForm">
		<div class="ui-widget ui-helper-clearfix">
			<label>订单号：</label><input type="text" name="orderNo" value="${order.orderNo}" class="ui-corner-all ui-widget-content" readonly="readonly">
		</div>
		<div id="orderItemWrapper" >
		
		</div>
		<input type="button" value="添加订单项" id="addOrderItemBtn">
		<input type="button" value="保存订单" id="addOrderItemBtn" onclick="$('#ordersForm').submit();">
	</form>
	<div id="dialog-information" title="信息提示" style="display:none;">
		<p><span class="ui-icon ui-icon-alert" style="float:left;"></span><span id="inform-content"></span></p>
	</div>
</body>
</html>